package singleinstance;

public class N {
    //懒汉式单例类：拿对象时，才创建对象
    //1.私有化构造器
    private N() {
    }
    //2.私有化静态变量
    private static N n;//n为null
    //3.提供静态方法返回该对象
    public static N getInstance() {
        if (n == null) {
            n = new N();
        }
        return n;
    }
}
